\defmodule {ContinuousDistChart}

This class provides tools to plot the density and the cumulative probability
 of a continuous probability distribution.


\bigskip\hrule
\begin{code}
\begin{hide}
/*
 * Class:        ContinuousDistChart
 * Description:  
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       Richard Simard
 * @since        May 2008

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.charts;
   import umontreal.iro.lecuyer.probdist.ContinuousDistribution;\begin{hide}

import org.jfree.chart.JFreeChart;
import javax.swing.JFrame;
\end{hide}


public class ContinuousDistChart \begin{hide} {
   protected ContinuousDistribution dist;
   protected double a,b;
   protected int m;
   protected XYLineChart cdfChart;
   protected XYLineChart densityChart;

   private void init() {
      double[][] cdf = new double[2][m+1];
      double[][] density = new double[2][m+1];
      double h = (b - a) / m;
      double x;
      int coex = 0;

      try {
         for (int i = 0; i <= m; i++) {
            x = a + i*h;
            cdf[0][i] = x;
            cdf[1][i] = dist.cdf (x);
         }
         cdfChart = new XYLineChart("cdf: " + dist.toString(), "", "", cdf);
      } catch (UnsupportedOperationException e) {
         coex++;
         System.err.println (e);
//         e.printStackTrace();
      }

      try {
         for (int i = 0; i <= m; i++) {
            x = a + i*h;
            density[0][i] = x;
            density[1][i] = dist.density (x);
         }
         densityChart = new XYLineChart("density: " + dist.toString(),
                                        "", "", density);
      } catch (UnsupportedOperationException e) {
         System.err.println (e);
         if (coex == 1)
            throw e;
      }
      cdfChart.setprobFlag (true);
      densityChart.setprobFlag (true);
   }
\end{hide}\end{code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsubsection*{Constructor}
\begin{code}

   public ContinuousDistChart (ContinuousDistribution dist, double a,
                               double b, int m) \begin{hide} {
      this.dist = dist;
      this.a = a;
      this.b = b;
      this.m = m;
      init();
   }\end{hide}
\end{code}
\begin{tabb}
 Constructor for a new \texttt{ContinuousDistChart} instance. It will plot the
% \externalclass{umontreal.iro.lecuyer.probdist}{ContinuousDistribution}
 continuous distribution \texttt{dist} over the interval $[a,b]$,
  using $m+1$ equidistant sample points.
\end{tabb}
\begin{htmlonly}
   \param{dist}{continuous distribution to plot}
   \param{a}{lower bound of interval}
   \param{b}{upper bound of interval}
   \param{m}{number of steps}
\end{htmlonly}

%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection*{Methods}

\begin{code}

   public JFrame viewCdf (int width, int height) \begin{hide} {
      return cdfChart.view(width, height);
   }\end{hide}
\end{code}
\begin{tabb}
   Displays a chart of the cumulative distribution function (cdf) on the screen
   using Swing. This method creates an application containing a chart panel
   displaying the chart. The created frame is positioned on-screen, and
   displayed before it is returned. The \texttt{width} and the \texttt{height}
   of the chart are measured in pixels.
\end{tabb}
\begin{htmlonly}
    \param{width}{frame width in pixels}
   \param{height}{frame height in pixels}
   \return{frame containing the chart}
\end{htmlonly}
\begin{code}

   public JFrame viewDensity (int width, int height) \begin{hide} {
      return densityChart.view(width, height);
   }\end{hide}
\end{code}
\begin{tabb}
    Similar to \method{viewCdf}{}, but for the probability density instead
   of the cdf.
\end{tabb}
\begin{htmlonly}
   \param{width}{frame width in pixels}
   \param{height}{frame height in pixels}
   \return{frame containing the chart}
\end{htmlonly}
\begin{code}

   public String toLatexCdf (int width, int height) \begin{hide} {
      return cdfChart.toLatex(width, height);
   }\end{hide}
\end{code}
\begin{tabb}
   Exports a chart of the cdf to a \LaTeX\ source code using PGF/TikZ.
   This method constructs and returns a string that can be written to
   a \LaTeX\ document to render the plot. \texttt{width} and \texttt{height}
   represents the width and the height of the produced chart. These dimensions
   do not take into account the axes and labels extra space. The \texttt{width}
   and the \texttt{height} of the chart are measured in centimeters.
\end{tabb}
\begin{htmlonly}
   \param{width}{Chart's width in centimeters}
   \param{height}{Chart's height in centimeters}
   \return{LaTeX source code}
\end{htmlonly}
\begin{code}

   public String toLatexDensity (int width, int height) \begin{hide} {
      return densityChart.toLatex(width, height);
   }\end{hide}
\end{code}
\begin{tabb}
   Similar to \method{toLatexCdf}{}, but for the probability density instead
   of the cdf.
\end{tabb}
\begin{htmlonly}
   \param{width}{Chart's width in centimeters}
   \param{height}{Chart's height in centimeters}
   \return{LaTeX source code}
\end{htmlonly}
\begin{code}

   public void setParam (double a, double b, int m) \begin{hide} {
      this.a = a;
      this.b = b;
      this.m = m;
      init();
   }\end{hide}
\end{code}
\begin{tabb}
   Sets the parameters $a$, $b$ and $m$ for this object.
\end{tabb}
\begin{htmlonly}
   \param{a}{lower bound of interval}
   \param{b}{upper bound of interval}
   \param{m}{number of points in the plot minus one}
\end{htmlonly}
\begin{code}
\begin{hide}
}\end{hide}
\end{code}
